<template>
    <el-form ref="ruleFormRef"  status-icon  label-width="120px" class="demo-ruleForm">
        <el-form-item label="账号" >
            <el-input v-model="login.name" />
        </el-form-item>
        <el-form-item label="密码" >
            <el-input v-model="login.password" type="password" autocomplete="off" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm">登陆</el-button>
        </el-form-item>
    </el-form>
</template>
<script setup lang="ts">
import { reactive} from 'vue'
import { ElForm,ElFormItem,ElButton,ElInput,ElMessage  } from 'element-plus'
import { useRouter } from 'vue-router'
import {loginApi} from '../../Api/login'

const router = useRouter()

const login = reactive({
  name:'',
  password:''
})

const submitForm =async () => {
  const {data,msg}=await loginApi(login);
  if(msg==='登录成功'){
    sessionStorage.setItem('power',JSON.stringify(data.power))
    ElMessage({
        type:'success',
        message:"登陆成功"
    })
    router.push('/home/student') 
  }else{
    ElMessage({
        type:'error',
        message:"账号或密码错误"
    })
  }
   
}

</script>